# Replication Package: Demographics, Capital Deepening, and the Allocation Puzzle

## Overview
This folder contains all files needed to replicate the analysis in "Demographics, Capital Deepening, and the Allocation Puzzle." The paper shows that the allocation puzzle (capital flowing uphill from poor to rich countries) is resolved by demographic stage: early-dividend countries attract capital (beta=+0.32***) while late-dividend countries export it (beta=-0.13***).

## Requirements
- Python 3.10+
- pandas, numpy, scipy, statsmodels
- Data files in data/processed/

## Structure
- `scripts/` — Analysis scripts (run in phase order)
- `src/` — Shared modules (PanelGLS estimator, data loading, country classifications)
- `data/processed/` — Processed panel data (deepening_panel.csv)
- `output/tables/` — Generated output tables
- `paper/` — Paper manuscript and references

## Reproduction
Run scripts in numerical phase order:
```
python scripts/phase1_data_assembly.py
python scripts/phase2_allocation_puzzle.py
python scripts/phase3_investment_channel.py
python scripts/phase4_tfp_mpk.py
python scripts/phase5_flow_composition.py
python scripts/phase6_absorptive_capacity.py
...
```

## Data Sources
- UN World Population Prospects 2024
- IMF World Economic Outlook
- Penn World Table 10.01 (use `rnna` for capital stock, NOT `ck`)
- Chinn-Ito KAOPEN Index
- Lane & Milesi-Ferretti External Wealth of Nations

## Notes
- All analysis uses the 140-country expanded panel (EBA-49 + SSA-20 + EU expansion + Tier 1 expansion)
- The `src/` modules are from the multilateral/followup project and contain the expanded country lists
- PWT capital stock uses `rnna` (constant 2017 national prices), NOT `ck` (normalized index=1)
- FDI drives K/L deepening; portfolio flows null
- Absorptive capacity: rule_of_law x demo_inflows interaction p=0.003
